home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 60914 / 60914.xpi / chrome / content / personasrotatorfileio.js < prev    next >
Text File  |  2010-01-20  |  2KB  |  78 lines

  1.  
  2.     var PersonasRotatorFileIO = {
  3.  
  4.         read:function(file,charset) {
  5.             
  6.             try {
  7.                 
  8.                 var scriptableInputStream = Components.classes['@mozilla.org/scriptableinputstream;1']
  9.                                     .createInstance(Components.interfaces.nsIScriptableInputStream);
  10.                 var fileInputStream = Components.classes['@mozilla.org/network/file-input-stream;1']
  11.                                     .createInstance(Components.interfaces.nsIFileInputStream);
  12.                 var data=new String();
  13.                 fileInputStream.init(file,1,0,false);
  14.                 scriptableInputStream.init(fileInputStream);
  15.                 data+=scriptableInputStream.read(-1);
  16.                 scriptableInputStream.close();
  17.                 fileInputStream.close();
  18.                 if (charset) {
  19.                     
  20.                     try {
  21.                         
  22.                         var scriptableUnicodeConverter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter']
  23.                                             .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  24.                         scriptableUnicodeConverter.charset = charset;
  25.                         data = scriptableUnicodeConverter.ConvertToUnicode(data);    
  26.                         
  27.                     } 
  28.                     
  29.                     catch(err) {/*do nothing*/}
  30.             
  31.                 }
  32.                 
  33.                 return data;
  34.                 
  35.             } 
  36.             
  37.             catch(err) {return false;}
  38.             
  39.         },
  40.  
  41.         write:function(file,data,mode,charset) {
  42.             
  43.             try {
  44.                 
  45.                 var fileOutputStream = Components.classes['@mozilla.org/network/file-output-stream;1']
  46.                                     .createInstance(Components.interfaces.nsIFileOutputStream);
  47.                 if (charset) {
  48.                     
  49.                     try {
  50.                         var scriptableUnicodeConverter = Components.classes['@mozilla.org/intl/scriptableunicodeconverter']
  51.                                             .createInstance(Components.interfaces.nsIScriptableUnicodeConverter);
  52.                         scriptableUnicodeConverter.charset = charset;
  53.                         data = scriptableUnicodeConverter.ConvertFromUnicode(data);
  54.                     }
  55.                     
  56.                     catch(err) {/*do nothing*/}
  57.  
  58.                 }
  59.                 
  60.                 var flags = 0x02 | 0x08 | 0x20;
  61.                 if (mode == 'a') {
  62.                     flags = 0x02 | 0x10;
  63.                 }
  64.                 
  65.                 fileOutputStream.init(file, flags, 0664, 0);
  66.                 fileOutputStream.write(data, data.length);
  67.                 fileOutputStream.close();
  68.                 
  69.                 return true;
  70.             }
  71.             
  72.             catch(err) {return false;}
  73.             
  74.         },
  75.  
  76.     }
  77.  
  78.